package com.oracle.controller;

import com.alipay.api.domain.OrderItem;
import com.oracle.Service.impl.FeedbackService;
import com.oracle.Service.impl.OrderItemService;
import com.oracle.entity.ResultBean;
import com.oracle.pojo.Feedback;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/feedback")
public class FeedbackController {

    @Autowired
    private FeedbackService feedbackService;


    @RequestMapping("/user/add")
    @ResponseBody
    public ResultBean addFeedBack(Feedback feedback){
        try{
            if (feedback!=null){
                Integer integer = feedbackService.addFeedBack(feedback);
                if (integer>0){
                    return ResultBean.success("修改成功",null);
                }
            }
            return ResultBean.getResultBean(300,"修改失败",null);
        }catch (Exception e){
            return ResultBean.fail("修改失败",null);
        }
    }

    @RequestMapping("/user/update")
    @ResponseBody
    public ResultBean updateFeedBack(Feedback feedback){
        try{
            if (feedback!=null){
                Integer integer = feedbackService.updateFeedBack(feedback);
                if (integer>0){
                    return ResultBean.success("修改成功",null);
                }
            }
            return ResultBean.getResultBean(300,"修改失败",null);
        }catch (Exception e){
            return ResultBean.fail("修改失败",null);
        }
    }


    @RequestMapping("/findFeedBackByUid")
    public String findFeedBacksByUid(Integer uid, Model model){
        try{
            if (uid!=null&&uid!=0){
                List<Feedback> list = feedbackService.findFeedBacksByUid(uid);
                if (list!=null){
                    model.addAttribute("feedbacks",list);
                    return "/admin/feedback";
                }
            }
            return "redirect:/user/userShow";
        }catch (Exception e){
            return "redirect:/user/userShow";
        }
    }
}
